#include<bits/stdc++.h>
using namespace std;
#define int long long

char ch[1005][1005];
int f[1005][1005];

signed main() {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> ch[i][j];

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (ch[i][j] == 'F')
				f[i][j] = max(f[i - 1][j], f[i][j - 1]) + 1;
			else
				f[i][j] = 0;
		}
	}
	cout << *max_element(&f[1][1], &f[n][m + 1]);
	return 0;
}
